package com.zyy.smartcity1129.bus;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.BusLineInfo;
import com.zyy.smartcity1129.data.BusStopInfo;

import java.util.List;

/**
 * @ClassName: BusUpDowmFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 5/12/2021$
 * @Version: 1.0
 */
public class BusUpDownFragment extends BaseFragment {
    private TextView tv1;
    private TextView tv2;
    private EditText edit1;
    private EditText edit2;
    private EditText edit3;
    private EditText edit4;
    private Button btn;
    private BusLineInfo.RowsBean busLine = BusFragment.line;
    private List<BusStopInfo.RowsBean> stop = BusFragment.stop;
    public static String name, phone, ups, downs;

    @Override
    protected int layId() {
        return R.layout.f_busupdown;
    }

    @Override
    protected String title() {
        return "信息输入";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return false;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        BusFragment.liveData.observe(getViewLifecycleOwner(), m -> {
            remove();
        });
        tv1.setText("起点：" + busLine.getFirst());
        tv2.setText("终点：" + busLine.getEnd());
        btn.setOnClickListener(view -> {
            name = edit1.getText().toString().trim();
            phone = edit2.getText().toString().trim();
            ups = edit3.getText().toString().trim();
            downs = edit4.getText().toString().trim();
            if (!name.equals("") && !phone.equals("") && !ups.equals("") && !downs.equals("")) {
                add(new BusConfirmFragment());
            } else {
                Toast.makeText(getContext(), "请输入全部信息", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView(View iv) {
        tv1 = (TextView) iv.findViewById(R.id.tv1);
        tv2 = (TextView) iv.findViewById(R.id.tv2);
        edit1 = (EditText) iv.findViewById(R.id.edit1);
        edit2 = (EditText) iv.findViewById(R.id.edit2);
        edit3 = (EditText) iv.findViewById(R.id.edit3);
        edit4 = (EditText) iv.findViewById(R.id.edit4);
        btn = (Button) iv.findViewById(R.id.btn);
    }
}
